package com.ux.abstract
{
	import com.ux.util.BitmapUtil;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	[ Event(type="DragBarEvent", name="verticalUpdate") ]
	[ Event(type="DragBarEvent", name="horizontalUpdate") ]
	
	public class ADragBar extends Sprite
	{
		
		protected var _enableScroll : Boolean = true;
		protected var _track : MovieClip;
		protected var _btn : MovieClip;
		protected var _downPoint : Number = 0;
		protected var _icon : MovieClip;
		protected var virtualBtnPoint : Point = new Point( 0, 0 );
		private var _scrollInterval : Number = 0;
		
		
		
		public function ADragBar()
		{
			super();
			
			_track = new MovieClip();
			_btn = new MovieClip();
			
			this.addEventListener( Event.ADDED_TO_STAGE, onStage );
		}
		
	
		public function get scrollInterval():Number
		{
			return _scrollInterval;
		}

		public function set scrollInterval(value:Number):void
		{
			_scrollInterval = value;
		}

		private function onStage( e:Event ):void 
		{
			this.addChild( track );
			this.addChild( btn );
			this.btn.buttonMode = true;
			
			this.btn.addEventListener(MouseEvent.MOUSE_DOWN, onDown );
		}
		
		
		
		
		
		
		
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// mouseHandler
		//
		//-----------------------------------------------------------------------------------
		
		protected function onDown( e:MouseEvent ):void 
		{
			if( stage == null ) return;
			
			this.setDownPoint();
			
			this.stage.addEventListener( MouseEvent.MOUSE_UP, onUp );
			this.stage.addEventListener( MouseEvent.MOUSE_MOVE, onMove );
		}
		
		protected function setDownPoint():void
		{
			
		}
		
		protected function onUp( e:MouseEvent ):void 
		{
			this.stage.removeEventListener( MouseEvent.MOUSE_UP, onUp );
			this.stage.removeEventListener( MouseEvent.MOUSE_MOVE, onMove );
		}
		
		
		protected function onMove( e:MouseEvent ):void 
		{
			this.btnMove( 0, true );
			this.setDownPoint();
		}
		
		
		
		/** value : btn의 위치를 강제 셋팅하는 값. **/
		public function btnMove( value:Number = 0, isDrag:Boolean=false ):void
		{
			
		}
		
		
		
		
		
		
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// api
		//
		//-----------------------------------------------------------------------------------
		
		public function set icon(value:MovieClip):void
		{
			if( _icon && this.contains( _icon ) )
			{
				removeChild( _icon );	
			}
			
			_icon = value;
			if( _icon != null )
			{
				_icon.mouseChildren = false;
				_icon.mouseEnabled = false;
				addChild( _icon );
				setIconPosition();
			}
		}
		
		public function get icon():MovieClip
		{
			return _icon;
		}
		
		
		/** 드래그 바 셋팅 **/
		public function set track( _trackClip:MovieClip ):void 
		{
			if( _track.numChildren != 0 ) _track.removeChild( _track.getChildAt( 0 ) );
			
			this._track.addChild( _trackClip );
		}
		
		/** 드래그 버튼 셋팅 **/
		public function set btn( _btnClip:MovieClip ):void 
		{
			if( this._btn.numChildren != 0 ) _btn.removeChild( _btn.getChildAt( 0 ) );
			
			this._btn.addChild( _btnClip );
		}
		
		
		public function get track():MovieClip 
		{
			if( this._track.numChildren == 0 )
			{
				this._track.addChild( BitmapUtil.MakeBitmap( 300, 20, 0xcccccc ) ); 
			}
			
			return this._track;
		}
		
		public function get btn():MovieClip 
		{
			if( this._btn.numChildren == 0)
			{
				this._btn.addChild( BitmapUtil.MakeBitmap( 40, 20, 0x000000 ) ); 
			}
			
			return this._btn;
		}
		
		public function btnReSize( contentsSize:Number ):void
		{
			
		}
		
		public function reset():void
		{
			
		}
		
		protected function setIconPosition():void
		{
			
		}
		
		
	}
}